#include <iostream>
#include <stack>
using namespace std;

stack<int> machine, box;
int n, m, k;

int main()
{
    cin >> n >> m >> k;
    stack<int> temp;
    int input;
    for (int i = 0; i < n; i++)
    {
        cin >> input;
        temp.push(input);
    }
    while (!temp.empty())
    {
        machine.push(temp.top());
        temp.pop();
    }
    while (1)
    {
        int first = -1;
        if (!box.empty())
        {
            first = box.top();
            box.pop();
        }
        else
        {
            if (!machine.empty())
            {
                first = machine.top();
                machine.pop();
            }
            else
            {
                break;
            }
        }
        cout << first;
        int cnt = 1;
        while (!box.empty() && box.top() <= first && cnt < k)
        {
            first = box.top();
            cout << " " << first;
            box.pop();
            cnt++;
        }
        while (!machine.empty() && cnt < k)
        {
            if (machine.top() <= first)
            {
                first = machine.top();
                cout << " " << first;
                machine.pop();
                cnt++;
            }
            else
            {
                if (box.size() < m)
                {
                    box.push(machine.top());
                    machine.pop();
                }
                else
                {
                    break;
                }
            }
        }
        cout << endl;
    }
    return 0;
}